#include "tts_config.h"

TTSConfig::~TTSConfig()
{
    //TODO
}


TTSConfig::TTSConfig(string file)
{
    init_qs(file);
    //TODO
}


int  TTSConfig::getVoiceID(string speaker)
{
    map<string,int>::iterator iterVoice;
	iterVoice = map_sp_vid.find(speaker);
	if(iterVoice!=map_sp_vid.end())
	{
        return iterVoice->second;
	}
	return -1;
}

void TTSConfig::init_qs(string file)
{
    cout<<"file:"<<file<<endl;
    Config_Base * config = Config_Base::instance();

    //string r_debug;
    string r_fs;
    string r_port;
    string r_speech_port;
    string r_worker_limit;
    string r_connection_limit;
	string sSpeaker;
	int  iVoiceID=0;
	int iIndex=0;
    config->Load(file.c_str());
    //config->Read(item_value,l_debug,r_debug);
    config->Read("global", "model_path", model_path);
    config->Read("global", "config_path", config_path);
    config->Read("global", "log_file",log_file);
    config->Read("global", "bind_address", bind_address);
    config->Read("global", "fs",r_fs);
    config->Read("global", "port",r_port);
    config->Read("global", "speech_port", r_speech_port);
    config->Read("global", "worker_limit", r_worker_limit);
    config->Read("global", "connection_limit", r_connection_limit);
    config->Read("global", "speaker_voiceid",sSpeaker);

    cout<<"speaker_voiceid:"<<sSpeaker<<endl;
    while(!sSpeaker.empty())
    {
        iIndex = sSpeaker.find(',',0);
	if(iIndex != string::npos)
	{
             map_sp_vid.insert(pair<string,int>(sSpeaker.substr(0,iIndex),iVoiceID++));
             cout<<"speake_v:"<<sSpeaker.substr(0,iIndex)<<":"<<iVoiceID<<endl;
	     sSpeaker = sSpeaker.substr(++iIndex);
	}
        else
        {  
            if(!sSpeaker.empty())
            {
                map_sp_vid.insert(pair<string,int>(sSpeaker,iVoiceID++));
	        cout<<"speake_v:"<<sSpeaker<<":"<<iVoiceID<<endl;
            }
	    break;
        }
    }
    fs = stoi(r_fs);
    port = stoi(r_port);
    speech_port = stoi(r_speech_port);
    worker_limit = stoi(r_worker_limit);
    connection_limit = stoi(r_connection_limit);
}


